package learnnet.jetty.simpleapplication;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.gson.Gson;

@WebServlet("/show")
public class MyTestServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = -6409412357295852195L;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {

		List<String> list = new ArrayList<String>();

		list.add("test1");
		list.add("test2");

		Gson g = new Gson();

		resp.setContentType("charset=gbk");
		ServletOutputStream out = resp.getOutputStream();
		String json = g.toJson(list);
		out.write(json.getBytes());
		out.flush();
		out.close();
	}

}
